package xcmg.device.service.crm.util;

import xcmg.device.infra.ErrorCode;
import yb.ecp.fast.infra.infra.ActionResult;

public class ActionResultUtil {


    public static ActionResult errorActionResult(int code, String msg){
        return actionResult(code,msg,null);
    }

    public static<T> ActionResult actionResult(int code, String msg, T value){
        return new ActionResult(code,msg,value);
    }

    public static ActionResult errorActionResult(ErrorCode errorCode){
        return errorActionResult(errorCode.getCode(),errorCode.getDesc());
    }

    public static ActionResult successActionResult(){
        return new ActionResult(ErrorCode.Success.getCode(), ErrorCode.Success.getDesc());
    }

    public static<T> ActionResult successActionResult(T obj){
        return new ActionResult(ErrorCode.Success.getCode(), ErrorCode.Success.getDesc(),obj);
    }

    /**
     * 判断是否为成功的返回*/
    public static boolean judgeSuccess(ActionResult result){
        if(result == null){
            return false;
        }
        try{
            int code = result.getCode();
            if(ErrorCode.Success.getCode() ==code){
                return true;
            }
            return false;
        }catch (Exception e){
            return false;
        }
    }
}
